﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Syspetro.Core.SysInterface
{
    public interface ILock
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="threadsingle">通过线程ID确保Key值唯一</param>
        /// <param name="expiry"></param>
        /// <returns></returns>
        bool Set(string key, TimeSpan? expiry = default, bool threadsingle = true);

        bool Get(string key);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="expiry">等待锁释放的时间</param>
        /// <returns></returns>
        Task<bool> GetAwait(string key, TimeSpan? expiry = default);
        /// <summary>
        /// 重置过期时间
        /// </summary>
        /// <param name="key"></param>
        /// <param name="expiry"></param>
        /// <returns></returns>
        bool Expire(string key, TimeSpan? expiry = default);

        bool Remove(string key, bool threadsingle = true);
    }
}
